program constraint_mode;

class packet;
    rand  bit [3:0] addr;
    
    constraint addr_range { addr inside {5,10,15}; }
endclass


initial begin
    packet pkt;
    pkt = new();

    $display("Before Constraint disable: ");
    $display("Value of constraint mode = %0d", pkt.addr_range.constraint_mode());
    repeat(5) begin
        pkt.randomize();
        $display("\taddr = %0d", pkt.addr);
    end

    // disabling constraint
    pkt.addr_range.constraint_mode(0);

    $display("After Constraint disable: ");
    $display("Value of constraint mode = %0d", pkt.addr_range.constraint_mode());
    repeat(5) begin
        pkt.randomize();
        $display("\taddr = %0d", pkt.addr);
    end
end

endprogram
